/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clases;

import java.util.regex.Pattern;

/**
 *
 * @author Sebas
 */
public class TipoValidaciones {

    public boolean es_email(String txt) {
        Pattern pc = Pattern.compile("^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$");
        return pc.matcher(txt).matches();
    }

    public boolean es_num(String txt) {
        Pattern pc = Pattern.compile("(-?\\d+)");
        return pc.matcher(txt.replaceAll(" ", "")).matches();
    }

    public boolean es_alfaNum(String txt) {
        Pattern pc = Pattern.compile("^[A-Z0-9 a-z]*$");
        return pc.matcher(txt).matches();
    }

    public boolean es_alfaBetico(String txt) {
        Pattern pc = Pattern.compile("^([a-záéíóúÁÉÍÓÚ\u00f1\u00d1A-Z]+\\s*)+$");
        return pc.matcher(txt).matches();
    }

    /**
     * Fecha viene en formato DIA / MES / AÑO dd-MM-AAAA
     * @param txt
     * @return 
     */
    public boolean es_fecha(String txt) {
        Pattern pc = Pattern.compile("((?:(?:[1]{1}\\d{1}\\d{1}\\d{1})|(?:[2]{1}\\d{3}))[-:\\/.](?:[0]?[1-9]|[1][012])[-:\\/.](?:(?:[0-2]?\\d{1})|(?:[3][01]{1})))(?![\\d])");
        return pc.matcher(txt).matches();
    }
    // Que permita nombre y apellido aparte o juntos

    public boolean es_nombreApellido() {
        return true;
    }

    public boolean si_vacio() {
        return true;
    }

    public boolean no_vacio() {
        return true;
    }

    public boolean es_vacio(String txt) {
        return (txt.isEmpty()) ? true : false;
    }

    public boolean es_menor(String eval, String vMin) {
        if (!"0".equals(vMin)) {
            return (eval.length() < Integer.parseInt(vMin)) ? true : false;
        } else {
            return false;
        }
    }

    public boolean es_mayor(String eval, String vMax) {
        if (!"0".equals(vMax)) {
            return (eval.length() > Integer.parseInt(vMax)) ? true : false;
        } else {
            return false;
        }
    }
}
